<?php


namespace App\Console\Commands;


use App\Models\Warranty;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class CarOwnerStatistics extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
        protected $signature = 'command:CarOwnerStat';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '车主统计';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $sql = 'select * from warranty_to_vehicle_coverage where film_type_id is null and roll_number is not null and deleted_at is null';
        $data = DB::select($sql);
        if (empty($data)) {
            return 0;
        }
        foreach ($data as $item) {
            $result = DB::table('roll_master')->where('roll_number', $item->roll_number)->first();
            if (empty($result)) {
                continue;
            }
            //dump($result);
            $updateResult = DB::table('warranty_to_vehicle_coverage')->where('id', $item->id)->update(['film_type_id' => $result->film_type_id]);
            dump($updateResult);
        }
    }
}